package com.qipay.baas.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.qipay.baas.model.SmsCode;

public class SmsCodeSqlProvider {

    public String insertSelective(SmsCode record) {
        BEGIN();
        INSERT_INTO("sms_code");
        
        if (record.getMobile() != null) {
            VALUES("mobile", "#{mobile,jdbcType=VARCHAR}");
        }
        
        if (record.getCode() != null) {
            VALUES("code", "#{code,jdbcType=VARCHAR}");
        }
        
        if (record.getIsUsed() != null) {
            VALUES("is_used", "#{isUsed,jdbcType=BIT}");
        }
        
        if (record.getInsertTime() != null) {
            VALUES("insert_time", "#{insertTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getMsgId() != null) {
            VALUES("msg_id", "#{msgId,jdbcType=INTEGER}");
        }
        
        if (record.getType() != null) {
            VALUES("`type`", "#{type,jdbcType=TINYINT}");
        }
        
        if (record.getTryCount() != null) {
            VALUES("try_count", "#{tryCount,jdbcType=INTEGER}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(SmsCode record) {
        BEGIN();
        UPDATE("sms_code");
        
        if (record.getMobile() != null) {
            SET("mobile = #{mobile,jdbcType=VARCHAR}");
        }
        
        if (record.getCode() != null) {
            SET("code = #{code,jdbcType=VARCHAR}");
        }
        
        if (record.getIsUsed() != null) {
            SET("is_used = #{isUsed,jdbcType=BIT}");
        }
        
        if (record.getInsertTime() != null) {
            SET("insert_time = #{insertTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getMsgId() != null) {
            SET("msg_id = #{msgId,jdbcType=INTEGER}");
        }
        
        if (record.getType() != null) {
            SET("`type` = #{type,jdbcType=TINYINT}");
        }
        
        if (record.getTryCount() != null) {
            SET("try_count = #{tryCount,jdbcType=INTEGER}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}